class Solution {
    public int maxProfit(int[] prices) {
        if(prices.length == 0) {
            return 0;
        }
        int length = prices.length;
        int[] s = new int[length];
        s[0] = 0;
        int min = prices[0];
        int max = 0;
        for(int i = 1;i < length;i++) {
            if(prices[i] > min) {
                int a = prices[i] - min;
                max = Math.max(a,max);
                s[i] = max;
            } else {
                min = prices[i];
                s[i] = 0;
            }
        }
        return max;
    }
}